<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core">
    <body>
        <p:commandButton  value="Cevap Ekle"  update="createReply"/>
	  <p:panel header="#{ForumBean.targetTopic.header}">
		    <h:panelGrid columnClasses="column1,column1" columns="2">
			  <h:panelGroup>
				<p:commandLink action="#{HomePageBean.clickStudent()}" ajax="false">
				    <h:graphicImage width="80" height="80" url="#{ForumBean.targetTopic.person.profilePicture}"/>
				    <f:setPropertyActionListener value="#{ForumBean.targetTopic.person}" target="#{StudentBean.target}"/>
				</p:commandLink>
				<h:panelGrid columns="2">
					  <h:outputLabel value="Adı: "/>
					  <p:commandLink value="#{ForumBean.targetTopic.person.fullName}" action="#{HomePageBean.clickStudent()}" ajax="false">
						 <f:setPropertyActionListener value="#{ForumBean.targetTopic.person}" target="#{StudentBean.target}"/>
					  </p:commandLink>
					   <h:outputLabel value="Tarih: "/>
                                           <h:outputLabel value="#{ForumBean.targetTopic.date.toLocaleString()}"/>
				    </h:panelGrid>
			  </h:panelGroup>
			  <h:panelGroup>
				<h:outputText escape="false" value="#{ForumBean.targetTopic.text}"/>
			  </h:panelGroup>
		    </h:panelGrid>
		<p:commandButton style="float:right;" rendered="#{ForumBean.sameStarter() or ForumBean.admin()}" value="Sil" ajax="false" action="#{ForumBean.deleteTopic()}"/>
		<p:commandButton style="float:right;" rendered="#{ForumBean.sameStarter() or ForumBean.admin()}" value="Düzenle" />
		</p:panel>
        <p:dataGrid columns="1" rowsPerPageTemplate="10,20,30,40" 
                      paginatorTemplate="{FirstPageLink}{PreviousPageLink} {PageLinks} {NextPageLink} {RowsPerPageDropdown}" value="#{ForumBean.targetTopic.replies}" var="reply">
		<p:column>
		<p:panel header="#{reply.header}">
                    <h:panelGrid columnClasses="column1,column1" columns="2">
			  <h:panelGroup>
				<h:panelGrid columns="1">
				<p:commandLink action="#{HomePageBean.clickStudent()}">
				    <h:graphicImage width="80" height="80" url="#{reply.user.profilePicture}"/>
				    <f:setPropertyActionListener value="#{reply.user}" target="#{StudentBean.target}"/>
				</p:commandLink>
				    <h:panelGrid columns="2">
					  <h:outputLabel value="Adı: "/>
					  <p:commandLink value="#{reply.user.fullName}" action="#{HomePageBean.clickStudent()}">
						 <f:setPropertyActionListener value="#{reply.user}" target="#{StudentBean.target}"/>
					  </p:commandLink>
					   <h:outputLabel value="Tarih: "/>
                                           <h:outputLabel value="#{reply.date.toLocaleString()}"/>
				    </h:panelGrid>
				</h:panelGrid>
			  </h:panelGroup>
			  <h:panelGroup>
				<h:outputText escape="false" value="#{reply.text}"/>
			  </h:panelGroup>
		    </h:panelGrid>
		    <p:commandButton style="float:right;" rendered="#{reply.same() or ForumBean.admin()}" value="Sil" ajax="false" action="#{ForumBean.deleteReply()}">
			  <f:setPropertyActionListener value="#{reply}" target="#{ForumBean.targetReply}"/>
		    </p:commandButton>
		    <p:commandButton style="float:right;" rendered="#{reply.same() or ForumBean.admin()}" value="Düzenle" />
		</p:panel>
		</p:column>
	  </p:dataGrid>
        <p:accordionPanel id="createReply" activeIndex="">
		<p:tab title="Cevap Yaz">
		<h:panelGrid columns="2">
		    <h:outputLabel value="Başlık: "/>
		    <p:inputText value="#{ForumBean.header}"/>
		</h:panelGrid>
		<p:editor value="#{ForumBean.text}"/>
		<p:commandButton value="Cevapla" action="#{ForumBean.addReply()}" ajax="false"/>
		</p:tab>
	  </p:accordionPanel>
    </body>
</html>
